package cn.ray.springframework.beans.factory.config;

import cn.ray.springframework.beans.PropertyValue;
import cn.ray.springframework.beans.PropertyValues;

public class BeanDefinition {
    String SCOPE_SINGLETON=ConfigurableBeanFactory.SCOPE_SINGLETON;
    String SCOPE_PROTOTYPE=ConfigurableBeanFactory.SCOPE_PROTOTYPE;

    private Class beanClass;

    private PropertyValues propertyValues;

    //为了在读取xml配置的bean对象中，完成xml语句的配置操作
    private String initMethodName;
    private String destroyMethodName;

    private String scope=SCOPE_SINGLETON;

    //用于把spring.xml中解析到的Bean对象作用范围填充到属性中
    private boolean singleton=true;
    private boolean prototype=false;

    public void setScope(String scope){
        this.scope=scope;
        this.singleton=SCOPE_SINGLETON.equals(scope);
        this.prototype=SCOPE_PROTOTYPE.equals(scope);
    }

    public boolean isSingleton(){
        return singleton;
    }

    public boolean isPrototype(){
        return prototype;
    }

    public BeanDefinition(Class beanClass) {
        this.beanClass = beanClass;
        this.propertyValues = new PropertyValues();
    }

    public BeanDefinition(Class beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues != null ? propertyValues : new PropertyValues();
    }

    public Class getBeanClass() {
        return beanClass;
    }

    public void setBeanClass(Class beanClass) {
        this.beanClass = beanClass;
    }

    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = propertyValues;
    }

    public String getInitMethodName() {
        return initMethodName;
    }

    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName;
    }

    public String getDestroyMethodName() {
        return destroyMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName;
    }
}
